package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.AWaringInfo;
import com.ruoyi.lock.service.IABuildHomeService;
import com.ruoyi.lock.service.IAWaringInfoService;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 预警信息Controller
 * 
 * @author ruoyi
 * @date 2024-08-06
 */
@RestController
@RequestMapping("/lock/info")
public class AWaringInfoController extends BaseController
{
    @Autowired
    private IAWaringInfoService aWaringInfoService;

    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private IABuildHomeService aBuildHomeService;

    /**
     * 查询预警信息列表
     */
//    @PreAuthorize("@ss.hasPermi('lock:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(AWaringInfo aWaringInfo)
    {
        startPage();
        List<AWaringInfo> list = aWaringInfoService.selectAWaringInfoList(aWaringInfo);
        // 过滤只返回故障上报和设备被撬两种类型的告警
//        List<AWaringInfo> filteredList = new ArrayList<>();
//        for (AWaringInfo info : list) {
//            if ("1".equals(info.getWaringType()) || "2".equals(info.getWaringType())) {
//                filteredList.add(info);
//            }
//        }
        return getDataTable(list);
    }

    @GetMapping("/listApp")
    public TableDataInfo listApp(AWaringInfo aWaringInfo)
    {
        startPage();
        List<AWaringInfo> list = aWaringInfoService.selectAWaringInfoListAPP(aWaringInfo);

        return getDataTable(list);
    }

    /**
     * 导出预警信息列表
     */
//    @PreAuthorize("@ss.hasPermi('lock:info:export')")
    @Log(title = "预警信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AWaringInfo aWaringInfo)
    {
        List<AWaringInfo> list = aWaringInfoService.selectAWaringInfoList(aWaringInfo);
        ExcelUtil<AWaringInfo> util = new ExcelUtil<AWaringInfo>(AWaringInfo.class);
        util.exportExcel(response, list, "预警信息数据");
    }

    /**
     * 获取预警信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('lock:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aWaringInfoService.selectAWaringInfoById(id));
    }

    /**
     * 新增预警信息
     */
//    @PreAuthorize("@ss.hasPermi('lock:info:add')")
    @Log(title = "预警信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AWaringInfo aWaringInfo)
    {
        return toAjax(aWaringInfoService.insertAWaringInfo(aWaringInfo));
    }

    /**
     * 修改预警信息
     */
//    @PreAuthorize("@ss.hasPermi('lock:info:edit')")
    @Log(title = "预警信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AWaringInfo aWaringInfo)
    {
        return toAjax(aWaringInfoService.updateAWaringInfo(aWaringInfo));
    }

    /**
     * 删除预警信息
     */
//    @PreAuthorize("@ss.hasPermi('lock:info:remove')")
    @Log(title = "预警信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids)
    {
        return toAjax(aWaringInfoService.deleteAWaringInfoByIds(ids));
    }
}
